<template>
  <button ref="tar" type="button" name="button" @click="testClick">
    {{ content }}
  </button>
</template>

<script>
export default {
  data() {
    return {
      content: "初始值2",
    };
  },
  methods: {
    testClick() {
      this.content = "改变了的值2";

      this.$nextTick((res) => {
        //dom元素更新后执行，因此这里能正确打印更改之后的值
        console.log(this.$refs.tar.innerText);
      });
    },
  },
};
</script>
